package operation;

import book.Book;
import book.BookLIst;

import java.util.Scanner;

public class ReturnBook implements Ioperation {
           public void work(BookLIst books){
               System.out.println("归还图书");
               System.out.println("输入你要归还的图书名称：");
               Scanner sc = new Scanner(System.in);
               String bookName = sc.nextLine();
               int currentSize = books.getUsedSize();
               for (int i = 0; i < currentSize; i++) {
                   Book book = books.getBook(i);
                   if(book.getName().equals(bookName)){
                       if(!book.isBorrowed()){
                           System.out.println("这本书还未被借出");
                       }else {
                           book.setBorrowed(false);
                           System.out.println("归还成功");
                           return;
                       }
                   }
               }
               System.out.println("没有你要归还的这本书");
           }
}
